﻿@model IEnumerable<KCMS.BusinessLogic.Models.AllowableProductSize>
@{
    ViewBag.Title = "Choose";
    ViewBag.Product = @Model.First().Product;
}
<h2>
    Выбирете размер для товара @ViewBag.Product.Article @ViewBag.Product.Title @ViewBag.Product.Brend.Title</h2>
@using (Html.BeginForm())
{
    foreach (var item in Model)
    {
    <span>
        <input type="checkbox" name="SizeList" value="@item.SizeId">
        @item.Size.Title
    </span>
    }
    <span>
        <input type="hidden" name="ProductId" value="@Model.First().ProductId">
    </span>
    <input type="button" id="choose-button" value="Сохранить" />
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#choose-button").click(function () {
            var array = [];
            
            $.each($("input[name='SizeList']:checked"), function () {
                var checkBox=$(this).val();
                array.push(checkBox);
            });
            var productId = $(this).closest("form").find("input[name='ProductId']").val();
            $.ajax({
                url: '@Url.Action("Choose", "AllowableProductSize")',
                type: "POST",
                data: JSON.stringify({Sizes:array,ProductId:productId}),
                dataType: "html",
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    window.location.replace("@Url.Action("Index","Product")")
                    /*new {productId=ViewBag.Product.Id})*/
                }
            });
        });

    });

</script>
